package com.spring5.testdemo;

import com.spring5.config.SpringConfig;
import com.spring5.service.UserService;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

@DisplayName("注解对象创建与属性注入")
public class TestSpring5Demo1 {

  @DisplayName("配置文件方式")
  @Test
  public void testService1() {
    ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
    UserService userService = context.getBean("userService", UserService.class);
    System.out.println(userService);
    userService.add();
  }

  @DisplayName("注解方式")
  @Test
  public void testService2() {
    // 加载配置类
    ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
    UserService userService = context.getBean("userService", UserService.class);
    System.out.println(userService);
    userService.add();
  }
}
